# 3.5 Photoresistor ## 3.5.1 Overview Photoresistor is photoelectric device that works according to semiconductor photoconductivity. It can be used to sense the brightness of the current environment to output a corresponding analog value. ## 3.5.2 Schematic Diagram ![t70](./media/t70.png) Photoresistor takes advantage of the photoelectric effect of semiconductors. Its resistance varies with ambient light. In the light, the semiconductor material absorbs photon energy to produce electron-hole pairs, increasing the conductivity and reducing the resistance. The brighter the light is, the lower the resistance will be. From the changes of resistance, it can sense light intensity accurately. Therefore, it is widely used in automatic lighting, photoelectric control, real-time monitoring and regulation of light. ## 3.5.3 Code Blocks Blocks in ![](./media/codingBox.png): 1. ![t71](./media/t71.png) is a block included in coding box library. It reads the analog value of the photoresistor in the coding box. The brighter the light is, the larger the analog value will be (Analog value range: 0-1023) ## 6.5.4 Test Code You can manually build blocks, or directly open the code file we provide: `3-5-Light.ubp`. If you have any questions about how to open code files or upload code, please back to `1.9 Upload Code`. **Build code blocks:** 1. In ![](./media/control.png), drag ![](./media/t1.png) and ![](./media/t2.png) to the script area, and stack them together. ![t34](./media/t34.png) 2. In ![](./media/output.png), drag ![t44](./media/t44.png) and ![t42](./media/t42.png) block and put them in ![](./media/t2.png). 3. Tap ![t47](./media/t47.png) of the ![t44](./media/t44.png) to add an output blank. In the first blank, enter `light value:` ![t72](./media/t72.png) 4. In ![](./media/codingBox.png), drag ![t71](./media/t71.png) and put it into both the second blank of ![t72](./media/t72.png) and ![t42](./media/t42.png). **Complete code:** ![t73](./media/t73.png) ## 3.5.5 Test Result Connect the coding box to the MicroBlocks via USB or Bluetooth, and click ![t59](./media/t59.png) to upload the code to the coding box. Click ![t11](./media/t11.png) to check the graph. Cover the sensor with your hand, and you will see the value decreases. ![t74](./media/t74.png)